import React, {Component} from 'react';
import Comment from './Comment'
import PropTypes from 'prop-types'

class CommentList extends Component {
    static propTypes  = {
        comments: PropTypes.array
    }
    constructor(props) {
        super(props)
        this.state = {
            childInfo: ''
        }
    }
    refreshPraent() {
        this.setState({
            childInfo: "子组件通信父组件成功",
        })
    }
    render() {
        const { comments } = this.props

        const page = comments.map(item => {
        return (
            <Comment key={item.id} comment={item} refreshPraent={this.refreshPraent.bind(this)}></Comment>
        );
      });

      return (
          <React.Fragment>
              <p>{this.state.childInfo}</p>
              {page}
          </React.Fragment>
      )
    }
}

export default CommentList;
